'------------------------------
' Hien thi 5 tin moi nhat
'------------------------------
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DotNetNuke
Namespace NVPortal.Modules.NVNews.Search

    Public MustInherit Class Settings
        Inherits DotNetNuke.Entities.Modules.ModuleSettingsBase


#Region "Event Handlers"
        Public Overrides Sub LoadSettings()
            Try


                If (Page.IsPostBack = False) Then

                    BindddlCategories()

                    If CType(ModuleSettings("NVNewsCategorySetting"), String) <> "" Then
                        Me.ddlCategory.Items.FindByValue(ModuleSettings("NVNewsCategorySetting")).Selected = True
                    End If
                    If IsNumeric(ModuleSettings("NVNewsDisplayPageSetting")) Then
                        Me.txtDisplayNewsPage.Text = ModuleSettings("NVNewsDisplayPageSetting")
                    End If

                    If CType(ModuleSettings("NVNewsDisplayStyleSetting"), String) <> "" Then
                        Me.ddlDisplayStyle.Items.FindByValue(ModuleSettings("NVNewsDisplayStyleSetting")).Selected = True
                    End If
                    If CType(ModuleSettings("NVNewsDisplayImageSetting"), String) <> "" Then
                        Me.rbtDisplayImage.Items.FindByValue(ModuleSettings("NVNewsDisplayImageSetting")).Selected = True
                    End If
                    If CType(ModuleSettings("NVNewsDisplayMarqueeSetting"), String) <> "" Then
                        Me.rbtMarquee.Items.FindByValue(ModuleSettings("NVNewsDisplayMarqueeSetting")).Selected = True
                    End If

                    If CType(ModuleSettings("NVNewsImageValueSetting"), String) <> "" Then
                        Me.txtImageWidth.Text = Split(ModuleSettings("NVNewsImageValueSetting"))(0)
                        Me.txtImageHeight.Text = Split(ModuleSettings("NVNewsImageValueSetting"))(1)
                    End If

                    If CType(ModuleSettings("NVNewsDisplayNumberSetting"), String) <> "" Then
                        Me.txtDisplayRow.Text = Split(ModuleSettings("NVNewsDisplayNumberSetting"))(0)
                        Me.txtDisplayCol.Text = Split(ModuleSettings("NVNewsDisplayNumberSetting"))(1)
                    End If
                End If

            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' UpdateSettings saves the modified settings to the Database
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        '''		[cnurse]	10/22/2004	created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public Overrides Sub UpdateSettings()
            Try
                Dim objModules As New DotNetNuke.Entities.Modules.ModuleController

                objModules.UpdateModuleSetting(ModuleId, "NVNewsCategorySetting", Me.ddlCategory.SelectedValue)
                If IsNumeric(Me.txtDisplayNewsPage.Text) Then
                    objModules.UpdateModuleSetting(ModuleId, "NVNewsDisplayPageSetting", Me.txtDisplayNewsPage.Text)
                End If
                objModules.UpdateModuleSetting(ModuleId, "NVNewsDisplayStyleSetting", Me.ddlDisplayStyle.SelectedValue)
                objModules.UpdateModuleSetting(ModuleId, "NVNewsDisplayImageSetting", Me.rbtDisplayImage.SelectedValue)
                objModules.UpdateModuleSetting(ModuleId, "NVNewsDisplayMarqueeSetting", Me.rbtMarquee.SelectedValue)
                objModules.UpdateModuleSetting(ModuleId, "NVNewsImageValueSetting", IIf(Trim(Me.txtImageWidth.Text) <> "", Trim(Me.txtImageWidth.Text), "0") & " " & IIf(Trim(Me.txtImageHeight.Text) <> "", Trim(Me.txtImageHeight.Text), "0"))
                objModules.UpdateModuleSetting(ModuleId, "NVNewsDisplayNumberSetting", IIf(Trim(Me.txtDisplayRow.Text) <> "", Trim(Me.txtDisplayRow.Text), "0") & " " & IIf(Trim(Me.txtDisplayCol.Text) <> "", Trim(Me.txtDisplayCol.Text), "0"))

            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

        Private Sub BindddlCategories()
            Dim ctlNewsCategories As New NV_NewsCategoriesController
            Dim arrNewsCategories As New ArrayList
            arrNewsCategories = ctlNewsCategories.GetAll(PortalId)
            Dim arrTemp As New ArrayList
            Dim objNewsCategories As NV_NewsCategoriesInfo
            Dim objNewsCategoriesTemp As NV_NewsCategoriesInfo

            If arrNewsCategories.Count > 0 Then
                For Each objNewsCategories In arrNewsCategories
                    If objNewsCategories.ParentId = 0 Then
                        arrTemp.Add(objNewsCategories)
                        For Each objNewsCategoriesTemp In arrNewsCategories
                            If objNewsCategoriesTemp.ParentId = objNewsCategories.CategoryID Then
                                objNewsCategoriesTemp.CategoryName = "--" & objNewsCategoriesTemp.CategoryName
                                arrTemp.Add(objNewsCategoriesTemp)
                            End If
                        Next
                    End If
                Next
            End If

            Me.ddlCategory.DataSource = arrTemp
            Me.ddlCategory.DataTextField = "CategoryName"
            Me.ddlCategory.DataValueField = "CategoryId"
            Me.ddlCategory.DataBind()

        End Sub

#End Region


    End Class

End Namespace
